<template>
	<view>
		<u-popup :safeAreaInsetBottom="true" :safeAreaInsetTop="true" :mode="popupData.mode" :show="show"
			:round="popupData.round" :overlay="popupData.overlay" :borderRadius="popupData.borderRadius"
			:closeable="popupData.closeable" :closeOnClickOverlay="popupData.closeOnClickOverlay" @close="close"
			@open="open" customStyle="background-image: linear-gradient(to top, #fff1eb 0%, #ace0f9 100%);">
			<view>
				<u-row>
					<span style="margin-left: 45%;">系统设置</span>
				</u-row>

			</view>

			<view class="u-popup-slot">
				<u--form labelPosition="left">
					<u-form-item label="MAC地址" labelWidth="85" prop="macAddr" borderBottom>
						<u--input v-model="macAddr" border="none"></u--input>
						<u-button @click="gotoScan" slot="right" :plain="true" icon="scan" text="扫描" type="primary"
							shape="circle" size="small" ></u-button>
					</u-form-item>

					<u-form-item label="左前传感器" labelWidth="85" prop="zuoqianRadio" borderBottom>
						<u-radio-group v-model="setedData.leftBefore" @change="roadChange">
							<u-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.name">
							</u-radio>
						</u-radio-group>
					</u-form-item>

					<u-form-item label="右前传感器" labelWidth="85" prop="youqianRadio" borderBottom>
						<u-radio-group v-model="setedData.rightBefore" @change="roadChange">
							<u-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.name">
							</u-radio>
						</u-radio-group>
					</u-form-item>

					<u-form-item label="左后传感器" labelWidth="85" prop="zuohouRadio" borderBottom>
						<u-radio-group v-model="setedData.leftAfter" @change="roadChange">
							<u-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.name">
							</u-radio>
						</u-radio-group>
					</u-form-item>

					<u-form-item label="右后传感器" labelWidth="85" prop="youhouRadio" borderBottom>
						<u-radio-group v-model="setedData.rigthAfter" @change="roadChange">
							<u-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in radiolist1"
								:key="index" :label="item.name" :name="item.name">
							</u-radio>
						</u-radio-group>
					</u-form-item>
				</u--form>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		props: {
		    setedData: {
		      type: Object, // 根据需要调整类型
		      default: undefined // 默认值
		    }
		  },
		data() {
			return {
				show: false,
				popupData: {
					overlay: true,
					mode: 'bottom',
					borderRadius: '10',
					closeable: true,
					closeOnClickOverlay: true,
					round: 10
				},
				radiolist1: [{
						name: '正接',
						disabled: false
					},
					{
						name: '反接',
						disabled: false
					}
				],
				macAddr: '',
				zuoqianRadio: '正接',
				youqianRadio: '正接',
				zuohouRadio: '反接',
				youhouRadio: '正接'


			}
		},
		created() {
			const deviceId=uni.getStorageSync("deviceId");
			this.macAddr=deviceId
		},
		methods: {
			gotoScan() {
				let that =this;
				uni.scanCode({
					success: function(res) {
						that.macAddr=res.result;
						that.$emit("pGetQrMac",res.result);
					}
				});
			},
			open() {
				this.show = true
			},
			close() {
				this.show = false
				// console.log('close');
			},
			roadChange(i) {
				this.saveData(this.setedData)
			},
			saveData(setedData){
				let content = setedData.rigthAfter+setedData.leftAfter+setedData.rightBefore+setedData.leftBefore;
				content = content.replaceAll('正接',0).replaceAll('反接',1);
				let decimalNumber = parseInt(content, 2); // 将二进制字符串转换为十进制数
				let hexString = decimalNumber.toString(16).toUpperCase();
				if (hexString.length < 2) {
					hexString = '0' + hexString;
				}
				this.$emit("pSensor",hexString);
			}
		}
	}
</script>

<style lang="scss">
	.u-popup-slot {
		width: 100%;
		height: 250px;
		@include flex;
		justify-content: center;
		align-items: center;
	}
</style>